package instance
{
	import view.GameObject;

	public class ResourcePool
	{
		
		private var pool:Vector.<GameObject> = new Vector.<GameObject>;
		private var poolSize:int = 100;
		private var newFunction:Function;
		
		public function ResourcePool(newFunction:Function,size:int)
		{
			this.newFunction = 	newFunction;
			this.poolSize = size;
		}
		
		
		
		public function newGameObject():GameObject {
			for(var go:GameObject in pool) {
				if(!go.inUse) {
					return go;
				}
			}
			
			if(pool.length<poolSize) {
				var obj:GameObject = newFunction();
				pool.push(obj);
				return obj;
			}
		}
	}
}

